package scc.Telas;

import Dao.UserDAO;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Davidson
 */
public class frmRelatorioPagamentosDiversos extends javax.swing.JInternalFrame {

    private static frmRelatorioPagamentosDiversos tela;
    private static UserDAO dao;
    
    /** Creates new form frmManutencaoDeUsuarios */
    private frmRelatorioPagamentosDiversos() {
        initComponents();
        this.setVisible(true);
        this.moveToFront();
        ftfDataInicial.setText(new SimpleDateFormat("dd/MM/yyyy").format(new Date())+" - 00:00");
        ftfDataFinal.setText(new SimpleDateFormat("dd/MM/yyyy").format(new Date())+" - 23:59");
    }
    
    public static frmRelatorioPagamentosDiversos getInstancia(UserDAO userDao){
        if (tela == null) {
            dao = userDao;
            tela = new frmRelatorioPagamentosDiversos();
        }
        return tela;
    }    
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bgSituacao = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        ftfDataInicial = new javax.swing.JFormattedTextField();
        imgDataInicial = new javax.swing.JLabel();
        ftfDataFinal = new javax.swing.JFormattedTextField();
        imgDataFinal = new javax.swing.JLabel();
        btExecutar = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        rbExcluidos = new javax.swing.JRadioButton();
        rbRegistrados = new javax.swing.JRadioButton();
        rbTodos = new javax.swing.JRadioButton();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Relatório - Pagamentos Diversos");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/scc/Imagens/currency_dollar_red.png"))); // NOI18N
        setMinimumSize(new java.awt.Dimension(758, 361));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Relatório de Lançamentos de Pagamentos Diversos"));

        jLabel1.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(51, 51, 51));
        jLabel1.setText("Data Inicial");

        jLabel2.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(51, 51, 51));
        jLabel2.setText("Data Final");

        jLabel3.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(51, 51, 51));
        jLabel3.setText("Período:");

        ftfDataInicial.setForeground(new java.awt.Color(51, 51, 51));
        try {
            ftfDataInicial.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/#### - ##:##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        ftfDataInicial.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        ftfDataInicial.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N

        imgDataInicial.setIcon(new javax.swing.ImageIcon(getClass().getResource("/scc/Imagens/calendar.png"))); // NOI18N
        imgDataInicial.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        imgDataInicial.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                imgDataInicialMouseClicked(evt);
            }
        });

        ftfDataFinal.setForeground(new java.awt.Color(51, 51, 51));
        try {
            ftfDataFinal.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/#### - ##:##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        ftfDataFinal.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        ftfDataFinal.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N

        imgDataFinal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/scc/Imagens/calendar.png"))); // NOI18N
        imgDataFinal.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        imgDataFinal.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                imgDataFinalMouseClicked(evt);
            }
        });

        btExecutar.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        btExecutar.setText("Executar");
        btExecutar.setPreferredSize(new java.awt.Dimension(99, 30));
        btExecutar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExecutarActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(51, 51, 51));
        jLabel4.setText("Situação:");

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        bgSituacao.add(rbExcluidos);
        rbExcluidos.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        rbExcluidos.setForeground(new java.awt.Color(51, 51, 51));
        rbExcluidos.setText("Lançamentos Excluídos");
        rbExcluidos.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        bgSituacao.add(rbRegistrados);
        rbRegistrados.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        rbRegistrados.setForeground(new java.awt.Color(51, 51, 51));
        rbRegistrados.setText("Lançamentos Registrados");
        rbRegistrados.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        bgSituacao.add(rbTodos);
        rbTodos.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        rbTodos.setForeground(new java.awt.Color(51, 51, 51));
        rbTodos.setSelected(true);
        rbTodos.setText("Todos os Lançamentos");
        rbTodos.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rbExcluidos)
                    .addComponent(rbRegistrados)
                    .addComponent(rbTodos))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rbExcluidos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbRegistrados)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbTodos)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(ftfDataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(imgDataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(ftfDataFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(imgDataFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel2)))
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btExecutar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(280, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(0, 0, 0)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(imgDataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ftfDataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ftfDataFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(imgDataFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addGap(1, 1, 1)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btExecutar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void imgDataInicialMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_imgDataInicialMouseClicked

        frmCalendar dialog = new frmCalendar(new javax.swing.JFrame(), false, ftfDataInicial);
        int x = getBounds().x;
        int y = getBounds().y;

        dialog.setBounds(x + 30, y + 183, 224, 140);
        dialog.setVisible(true);
    }//GEN-LAST:event_imgDataInicialMouseClicked

    private void imgDataFinalMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_imgDataFinalMouseClicked
        frmCalendar dialog = new frmCalendar(new javax.swing.JFrame(), false, ftfDataFinal);
        int x = getBounds().x;
        int y = getBounds().y;

        dialog.setBounds(x + 210, y + 183, 224, 140);
        dialog.setVisible(true);
    }//GEN-LAST:event_imgDataFinalMouseClicked

    private void btExecutarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExecutarActionPerformed
        String di = ftfDataInicial.getText();
        String df = ftfDataFinal.getText();
        int situacao = 0;
        if (rbExcluidos.isSelected()) situacao = 1;
        if (rbRegistrados.isSelected()) situacao = 0;
        if (rbTodos.isSelected()) situacao = 2;        
        
        String dt1 = di.substring(6,10)+"-"+di.substring(3,5)+"-"+di.substring(0,2)+" "+di.substring(13)+".000";
        String dt2 = df.substring(6,10)+"-"+df.substring(3,5)+"-"+df.substring(0,2)+" "+df.substring(13)+".997";        
                
        String file = "./jasper/RelatorioPagamentosDiversos.jasper";
        String titulo = "Relatório - Pagamentos Diversos";

        JasperPrint jp;
        try {
            HashMap parametros = new HashMap();
            parametros.put("excluido", situacao);
            parametros.put("dtini", dt1);
            parametros.put("dtfim", dt2);
            jp = JasperFillManager.fillReport(file, parametros, dao.getConnection());
            JasperViewer jv = new JasperViewer(jp, false);
            jv.setTitle(titulo);
            JDialog view = new JDialog(new javax.swing.JFrame(), titulo, true);
            Toolkit tollkit = Toolkit.getDefaultToolkit();
            Dimension dimensao = tollkit.getScreenSize();
            view.setSize((int)dimensao.getWidth(), (int)(dimensao.getHeight()*0.95));
            view.getContentPane().add(jv.getContentPane());
            view.setVisible(true);            
        } catch (JRException ex) {
            Logger.getLogger(frmCaixa.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this.getParent(), ex.toString());
        }
    }//GEN-LAST:event_btExecutarActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgSituacao;
    private javax.swing.JButton btExecutar;
    private javax.swing.JFormattedTextField ftfDataFinal;
    private javax.swing.JFormattedTextField ftfDataInicial;
    private javax.swing.JLabel imgDataFinal;
    private javax.swing.JLabel imgDataInicial;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton rbExcluidos;
    private javax.swing.JRadioButton rbRegistrados;
    private javax.swing.JRadioButton rbTodos;
    // End of variables declaration//GEN-END:variables
}
